package com.example.springboot.document;

import com.example.springboot.exception.BaseException;

/**
 * @Description: ResultBo
 * @Author wenlinyu
 * @Date: 2020/12/16 15:39
 * @Version 1.0
 */
public class ResultBo<T> {

    private Integer code;
    private String msg;
    private T data;

    public ResultBo() {
        this.code = 0;
        this.msg = "操作成功";
    }

    public ResultBo(T data) {
        this();
        this.data = data;
    }

    public ResultBo(Exception ex) {
        if (ex instanceof BaseException) {
            this.code = ((BaseException)ex).getCode();
            this.msg = ((BaseException)ex).getMsg();
        } else {
            this.code = 99999;
            this.msg = ex.getMessage();
        }
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
